package com.didispace;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.test.SpringApplicationConfiguration;
import org.springframework.integration.support.MessageBuilder;
import org.springframework.messaging.Message;
import org.springframework.messaging.MessageChannel;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.web.WebAppConfiguration;

@RunWith(SpringJUnit4ClassRunner.class)
@SpringApplicationConfiguration(classes = HelloApplication.class)
@WebAppConfiguration
//@DirtiesContext
public class HelloApplicationTests3 {

	@Autowired @Qualifier("input")
	private MessageChannel output;

	@Autowired @Qualifier("myinput")
	private MessageChannel myoutput;
	@Autowired @Qualifier("myinput1")
	private MessageChannel myoutput1;
	@Test
	public void contextLoads() {
		Message<String> message = MessageBuilder.withPayload("{\"name\":\"didi\", \"age\":30}").build();
		ScheduledExecutorService service = Executors.newScheduledThreadPool(12);
		for(int i=0 ;i<12;i++){
			service.scheduleAtFixedRate(new Runnable(){
				@Override
				public void run() {
					output.send(message);
					myoutput.send(message);
					myoutput1.send(message);
				}
			},
			1000L,
			1000L,
			TimeUnit.MILLISECONDS
			);
			
		}
		System.out.println("ddd");
	}

}
